package com.example.administrator.twopagelibrary.dagger;

import android.app.Activity;

import com.example.administrator.commonlibrary.bese.BaseAppliction;
import com.example.administrator.twopagelibrary.dagger.component.ActivityComponent;
import com.example.administrator.twopagelibrary.dagger.component.DaggerActivityComponent;
import com.example.administrator.twopagelibrary.dagger.module.ViewModule;
import com.example.administrator.twopagelibrary.dagger.module.ViewParameterModule;
import com.example.administrator.twopagelibrary.twobase.MainActivity;
import com.example.administrator.twopagelibrary.view.activity.MIntent2Activity;
import com.example.administrator.twopagelibrary.view.activity.MIntentActivity;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/17
 * 描述：
 */
public class NewActivityInject implements ActivityComponent {

    private ActivityComponent build;

    public static NewActivityInject getInject(){
        return new NewActivityInject();
    }
    public  <S, T> void inject(S module, T context) {
        if (module == null) module = (S) new ViewParameterModule((Activity) context);
         ViewModule mvpModule = new ViewModule((Activity) context);
        build = DaggerActivityComponent.builder().viewModule(mvpModule).viewParameterModule((ViewParameterModule) module).overallSituationComponent(BaseAppliction.getOverallSituation()).build();
        if (context instanceof MainActivity)inject((MainActivity)context);
        if (context instanceof MIntentActivity)inject((MIntentActivity)context);
        if (context instanceof MIntent2Activity)inject((MIntent2Activity)context);
    }

    @Override
    public void inject(MIntentActivity mIntentActivity) {
        build.inject(mIntentActivity);
    }

    @Override
    public void inject(MainActivity mainActivity) {
        build.inject(mainActivity);
    }

    @Override
    public void inject(MIntent2Activity mIntent2Activity) {
        build.inject(mIntent2Activity);
    }
}
